<template>
  <div>
    <el-dialog v-model="visible" :title="title" width="50%">
      <div style="padding-right: 30px;">
        <el-form :model="form">
          <el-form-item label="初始账号" :label-width="formLabelWidth">
            <el-input v-model="form.initialAccount" />
          </el-form-item>
          <el-form-item label="初始密码" :label-width="formLabelWidth">
            <el-input v-model="form.initialPassword" />
          </el-form-item>
          <el-form-item label="会员到期时间" :label-width="formLabelWidth">
            <!--          <el-input v-model="form.expireTime" />-->
            <el-date-picker
                v-model="form.expireTime"
                type="date"
                placeholder="请选择会员到期时间"
                style="width:100%"
            />
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="visible = false">取消</el-button>
          <el-button type="primary" @click="submitForm">确认</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus';
import { ref, defineExpose, defineEmits} from 'vue';
import BsApply from '../../../api/guild/bsApply';
const visible=ref(false)
const title=ref('')
const formLabelWidth = '140px'
// 表单默认值
let defaultForm = {
  id: '',
  initialAccount: '',
  initialPassword: '123456',
  expireTime: '',
}
let form = ref(defaultForm)
//打开分配账号框
function open(row){
    form.value={...defaultForm}
    title.value='分配账号'
    form.value.id=row.id
    form.value.initialAccount = row.unitName
    visible.value=true
}
let emit = defineEmits(['refresh'])
//分配账号
async function submitForm(){
    try{
        await ElMessageBox.confirm(
            '确定提交吗',
            '重要提示',
            {
                confirmButtonText:'确定',
                cancelButtonText:'取消',
                type:'warning'
            }
        )
        let formData=JSON.parse(JSON.stringify(form.value))
            try{
                let res=await BsApply.allocate(formData)
                ElMessage.success(res.data)
                visible.value=false
                emit('refresh')
            }catch(e){
                console.log("e",e)
                ElMessage.error(e)
            }
    }catch(e){

    }
}
defineExpose({
    open
})
</script>